
package time.basic;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

/**
 * Time series chart sample code<br>
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class FirstTimeSeriesChart
{
	private String housePriceLengendLabel = "房價指數";

	private String title = "房價指數圖";

	private String timeAxisLabel = "估價日期";

	private String valueAxisLabel = "總價(萬元)";

	public FirstTimeSeriesChart()
	{
		JFreeChart chart = createTimeSeriesChart();

		display( chart );
	}

	/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		new FirstTimeSeriesChart();
	}

	private JFreeChart createTimeSeriesChart()
	{
		TimeSeries housePriceTS = new TimeSeries( housePriceLengendLabel, Month.class );
		housePriceTS.add( new Month( 2, 2001 ), 181.8 );
		housePriceTS.add( new Month( 3, 2001 ), 210.3 );
		housePriceTS.add( new Month( 4, 2001 ), 153.8 );
		housePriceTS.add( new Month( 5, 2001 ), 167.6 );
		housePriceTS.add( new Month( 6, 2001 ), 158.8 );
		housePriceTS.add( new Month( 7, 2001 ), 148.3 );
		housePriceTS.add( new Month( 8, 2001 ), 153.9 );
		housePriceTS.add( new Month( 9, 2001 ), 142.7 );
		housePriceTS.add( new Month( 10, 2001 ), 123.2 );
		housePriceTS.add( new Month( 11, 2001 ), 131.8 );
		housePriceTS.add( new Month( 12, 2001 ), 139.6 );
		housePriceTS.add( new Month( 1, 2002 ), 142.9 );
		housePriceTS.add( new Month( 2, 2002 ), 138.7 );
		housePriceTS.add( new Month( 3, 2002 ), 137.3 );
		housePriceTS.add( new Month( 4, 2002 ), 143.9 );
		housePriceTS.add( new Month( 5, 2002 ), 139.8 );
		housePriceTS.add( new Month( 6, 2002 ), 137.0 );
		housePriceTS.add( new Month( 7, 2002 ), 132.8 );

		TimeSeriesCollection dataset = new TimeSeriesCollection();
		dataset.addSeries( housePriceTS );

		return ChartFactory.createTimeSeriesChart( title, timeAxisLabel, valueAxisLabel, dataset, true, true, false );
	}

	private void display( JFreeChart chart )
	{
		ChartFrame frame = new ChartFrame( "Test", chart );
		frame.pack();
		frame.setVisible( true );
	}
}
